﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.ServiceLocation;
using System.Windows.Controls;

namespace Dynamic_UI_Framework
{
    public abstract class Bootstrapper
    {
        public Bootstrapper(Setting setting)
        {
            UISetting.setting = setting;
        }

        public void Run()
        {
            this.Run(true);
        }
        protected virtual void ConfigureRegionAdapterMappings()
        {
            LayoutAdapterMapping layoutAdapterMappings = ServiceLocator.Current.GetInstance<LayoutAdapterMapping>();
            if (layoutAdapterMappings != null)
            {
                layoutAdapterMappings.RegisterMapping(typeof(DockPanel), ServiceLocator.Current.GetInstance<DockPanelLayoutAdapter>());
            }

            BenchAdapterMapping benchAdapterMappings = ServiceLocator.Current.GetInstance<BenchAdapterMapping>();
            if (benchAdapterMappings != null)
            {
                benchAdapterMappings.RegisterMapping(typeof(UserControl), ServiceLocator.Current.GetInstance<UserControlBenchAdapter>());
            }
            RegionAdapterMapping regionAdapterMappings = ServiceLocator.Current.GetInstance<RegionAdapterMapping>();
            if (regionAdapterMappings != null)
            {
                regionAdapterMappings.RegisterMapping(typeof(UserControl), ServiceLocator.Current.GetInstance<UserControlRegionAdapter>());
                regionAdapterMappings.RegisterMapping(typeof(TabControl), ServiceLocator.Current.GetInstance<TabControlRegionAdapter>());
                regionAdapterMappings.RegisterMapping(typeof(TabItem), ServiceLocator.Current.GetInstance<TabItemRegionAdapter>());

            }

            PanelAdapterMapping panelAdapterMappings = ServiceLocator.Current.GetInstance<PanelAdapterMapping>();
            if (panelAdapterMappings != null)
            {
                panelAdapterMappings.RegisterMapping(typeof(DesignerCanvas), ServiceLocator.Current.GetInstance<CanvasPanelAdapter>());
                panelAdapterMappings.RegisterMapping(typeof(Grid), ServiceLocator.Current.GetInstance<GridPanelAdapter>());
            }

            DesignerItemAdapterMapping designerItemAdapterMappings = ServiceLocator.Current.GetInstance<DesignerItemAdapterMapping>();
            if (designerItemAdapterMappings != null)
            {
                designerItemAdapterMappings.RegisterMapping(typeof(DesignerItemControl), ServiceLocator.Current.GetInstance<DesignerItemAdapter>());
            }
        }
        public abstract void Run(bool runWithDefaultConfiguration);
        protected abstract void ConfigureServiceLocator();

        public abstract object GetRootBench();
    }
}
